package com.example.it.review;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.example.it.review.acvitity.control.ButtonActivity;
import com.example.it.review.acvitity.control.EditTextActivity;
import com.example.it.review.acvitity.control.ProgressBarActivity;
import com.example.it.review.acvitity.control.RadioButtonAndCheckBoxActivity;
import com.example.it.review.acvitity.control.RatingBarActivity;
import com.example.it.review.acvitity.control.SeekBarActivity;
import com.example.it.review.acvitity.control.TextViewActivity;
import com.example.it.review.acvitity.control.ToggleAndSwitchActivity;
import com.example.it.review.adapter.MyAdapter;

import java.util.ArrayList;
import java.util.List;

public class HomeActivity extends AppCompatActivity implements View.OnClickListener {

    private RecyclerView rv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        initFindView();
        init();
    }

    void initFindView() {
        rv = (RecyclerView) this.findViewById(R.id.rv);
    }

    void init() {
        List<String> stringList = new ArrayList<>();

        stringList.add("TextView");
        stringList.add("EditText");
        stringList.add("Button");
        stringList.add("RadioButtonAndCheckBox");
        stringList.add("ToggleAndSwitchActivity");
        stringList.add("ProgressBar");
        stringList.add("SeekBar");
        stringList.add("RatingBar");

        MyAdapter adapter = new MyAdapter(this, stringList, this);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.setAdapter(adapter);
    }

    @Override
    public void onClick(View view) {
        Class c = null;
        TextView textView = (TextView) view;
        switch (textView.getText().toString()) {
            case "TextView":
                c = TextViewActivity.class;
                break;
            case "EditText":
                c = EditTextActivity.class;
                break;
            case "Button":
                c = ButtonActivity.class;
                break;
            case "RadioButtonAndCheckBox":
                c = RadioButtonAndCheckBoxActivity.class;
                break;
            case "ToggleAndSwitchActivity":
                c = ToggleAndSwitchActivity.class;
                break;
            case "ProgressBar":
                c = ProgressBarActivity.class;
                break;
            case "SeekBar":
                c = SeekBarActivity.class;
                break;
            case "RatingBar":
                c = RatingBarActivity.class;
                break;
        }

        Intent intent = new Intent(this, c);
        this.startActivity(intent);
    }
}
